﻿using System;
using System.Web;
using System.Collections;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace com.fly.sms
{
    public abstract class BaseAction:IAction
    {
        //分页页号
        protected int pNo;
        //分页大小
        protected int pagePerSize;
        //数据查询开始行
        protected int startRow;
        // 当前访问客户Id,与会话session绑定
        protected string CustomerId;
        protected Hashtable ht = new Hashtable();
        protected HttpContext context;
        //生成唯一id
        protected string guid = StringUtil.GetOID();
        public BaseAction(HttpContext contextTemp)
        {
            this.context = contextTemp;
        }
        public BaseAction()
        {
           
        }
        public void process() {
            try
            {

                //会话参数
                string sessionkey = context.Request["sessionkey"];
                CustomerId = context.Request["CustomerId"];
                //分页参数处理pNo,pSize,startRow
                pNo = int.Parse(StringUtil.isEmpty(context.Request["pNo"]) ? "1" : context.Request["pNo"]);
                pagePerSize = int.Parse(StringUtil.isEmpty(context.Request["pSize"]) ? "10" : context.Request["pSize"]);
                if (pagePerSize <= 0)
                {
                    pagePerSize = 10;
                }
                if (pNo <= 0)
                {
                    pNo = 1;
                }
                startRow = (pNo - 1) * pagePerSize;
                //是否登录检查
                bool login = true;
                if (!login)
                {//未登录，无权限执行
                    ht.Add("responseCode", "200");
                    ht.Add("responseData", "未获得授权，非法调用!");
                    string json = JsonConvert.SerializeObject(ht);
                    context.Response.Write(json);
                    return;
                }
                excute();
            }catch(Exception e)
            {
                ht.Add("responseData", e.Message);
                ht.Add("responseCode", "500");
                String json = JsonConvert.SerializeObject(ht);
                context.Response.Write(json);
            }
            
        }
        public abstract void excute();
    }
}